<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
	<title>Destroydrop &raquo; Javascripts &raquo; Tree</title>

	<link rel="StyleSheet" href="${base}/admin/dtree/dtree.css" type="text/css" />
	<script type="text/javascript" src="${base}/admin/js/jquery-1.7.min.js"></script>
	<script type="text/javascript" src="${base}/admin/dtree/dtree.js"></script>
	<script type="text/javascript" src="${base}/admin/contextmenu/jquery.contextmenu.js"></script>
	
	<style type="text/css">
		* {font-size:13px;}
		.contextMenu{display.none;}
	</style>

</head>

<body>
<div class="dtree">

	<script type="text/javascript">

		d = new dTree('d');		
		d.add(0,-1,'<span sytle="font-size:30px;"><b>店铺分类列表</b></span>','store_list.action','点击查看所有店铺','category_main');
		
		<#list brandCategoryList as category>
			d.add(${treeMap[category.id]},${(treeMap[category.parent.id])!'0'},'${(category.name)!''}','brand_list.action?cid=${category.id}','点击查看','category_main','dtree/img/folder.gif','dtree/img/folderopen.gif');
		</#list>
		
		document.write(d);
			
	</script>

</div>

<div class="contextMenu" id="dtreeMenu">
	<ul>
		<li id="open_close"><img src="contextmenu/folder.png" /> <span id="o_c">打开</span></li>
		<li id="addBrand"><img src="contextmenu/email.png" /> 添加品牌</li>
		<li id="viewCategory"><img src="contextmenu/disk.png" /> 分类信息</li>
		<li id="addCatetory"><img src="contextmenu/disk.png" /> 添加分类</li>
		<li id="deleteCatetory"><img src="contextmenu/disk.png" /> 删除分类</li>
		<li id="sortCatetory"><img src="contextmenu/disk.png" /> 分类排序</li>
		<li id="flush"><img src="contextmenu/disk.png" /> 刷新分类</li>
	</ul>
</div>
<div class="contextMenu" id="documentMenu">
	<ul>
		<li id="openAll"><img src="contextmenu/folder.png" /> 打开所有</li>
		<li id="closeAll"><img src="contextmenu/folder.png" /> 关闭所有</li>
		<li id="allBrand"><img src="contextmenu/folder.png" /> 所有品牌</li>
		<li id="addCategory"><img src="contextmenu/email.png" /> 添加分类</li>
		<li id="addBrand"><img src="contextmenu/email.png" /> 添加品牌</li>
		<li id="sortCatetory"><img src="contextmenu/disk.png" /> 分类排序</li>
		<li id="flushSecend"><img src="contextmenu/disk.png" /> 刷新分类</li>
	</ul>history.go(0) 
</div>

<script text="text/javascript">

	var currNodeId;
	var currCid;
	$(".dtree").find("a").contextMenu('dtreeMenu',{
		onContextMenu: function(e){
			currNodeId=e.target.id.substr(d.obj.length+1);
			currCid=getParameter("cid",e.target.toString());
			if(d.isOpen(currNodeId)){
				$("#o_c").html("关闭");
			}else{
				$("#o_c").html("打开");
			}
			return true;
		},
		bindings: {
			'open_close':function(t){
				d.o(currNodeId);
			},
			'viewBrand':function(t){
				parent.category_main.location.href=t.toString();
			},
			'addBrand':function(t){
				parent.category_main.location.href="brand_input.action?cid="+currCid;
			},
			'viewCategory':function(t){
				parent.category_main.location.href="brandCategory_view.action?id="+currCid;
			},
			'addCatetory':function(t){
				parent.category_main.location.href="brandCategory_input.action?id="+currCid;
			},
			'flush':function(t){
				location.href="javascript:history.go(0)";
			},
			'sortCatetory':function(t){
				parent.category_main.location.href="brandCategory_sort_list.action?parentId="+currCid;
			},
			'deleteCatetory':function(t){
				if(confirm("确实要删除该分类吗？此操作将不可恢复！")){
					$.post("brandCategory_delete.action",{id:currCid},function(data){
						data=eval(data);
						if(data[0].status=="success"){
							alert(data[0].message);
							history.go(0);
						}else{
							alert(data[0].message);
						}
					});
				}
			}
		}
	});

	$(document).contextMenu('documentMenu',{
		onContextMenu: function(e){
			return true;
		},
		bindings: {
			'openAll':function(t){
				d.openAll();
			},
			'closeAll':function(t){
				d.closeAll();
			},
			'allBrand':function(t){
				parent.category_main.location.href="brand_list.action";
			},
			'addCategory':function(t){
				parent.category_main.location.href="brandCategory_input.action";
			},
			'addBrand':function(t){
				parent.category_main.location.href="brand_input.action";
			},
			'flushSecend':function(t){
				location.href="javascript:history.go(0)";
			},
			'sortCatetory':function(t){
				parent.category_main.location.href="brandCategory_sort_list.action";
			}
		}
	});
	
	//获取指定参数名和URL获得参数值
	function getParameter(parameterName,parameterString){
		//这样可以保证第一个参数也能分出来
		parameterString = parameterString.replace("?","?&").split("&");
		var re = "";
		for(i=1;i<parameterString.length;i++){
		    if(parameterString[i].indexOf(parameterName+"=")==0){
		    	//取代前面的参数名，只剩下参数值
		        re = parameterString[i].replace(parameterName+"=","");
		    }
		}
		return re;
	};

</script>

</body>

</html>